<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList, java.util.Iterator" %>
<%@ page import="util.Helper,pojo.ItemAttr" %>
<%
    Object objTotalPoll  = request.getAttribute("totalPoll");
    int totalPoll   = 1;
    if(objTotalPoll != null) {
        totalPoll   = Helper.obj2Int(objTotalPoll);
        if(totalPoll == 0) {
            totalPoll = 1;
        }
    }
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>投票统计</title>
<link rel="stylesheet" href="../css/base.css" />
<style type="text/css">
    .poll_count table{
        margin: 0px auto;
        text-align: center;
    }
    .title_1 {
        text-align: center;
    }
</style>
</head>
<body>
    <div class="wrap">
        <div class="header">
            <p class="tool_bar">
                <a href="javascript:location.reload();">[刷新]</a>
                <a href="javascript:history.go(-1);">&lt;&lt;返回上一页</a>
                <a href="../index">返回主页&gt;&gt;</a>
                <a href="../logout">[退出]</a>
            </p>
            <h1>投票统计情况</h1>
        </div>
        <div class="content">
            <div class="poll_count">
              <%
                   Object obj   = request.getAttribute("items");
                   if(obj == null) {
                       out.print("投票还没开放！");
                   } else {
                       out.print("<table cellspacing='3' cellpadding='3' border='1' width='500'>");
                       out.print("<tr><td colspan='3' class='title_1'>得票情况<sub>(总票数：" +
                                  totalPoll + ")</sub></td></tr>");
                       out.print("<tr><td>项目名称</td><td>得票数</td><td>百分比</td></tr>");
                       ArrayList<ItemAttr> items  = (ArrayList<ItemAttr>)obj;
                       Iterator<ItemAttr> iItems  = items.iterator();
                       while(iItems.hasNext()) {
                           ItemAttr item    = (ItemAttr)iItems.next();
                           String itemName  = item.getItemName();
                           int itemPoll     = item.getItemPoll();
                           out.print("<tr><td>");
                           out.print(itemName);
                           out.print("</td><td>");
                           out.print(itemPoll);
                           out.print("</td><td>");
                           out.print((float)itemPoll/totalPoll * 100);
                           out.print("%</td></tr>");
                           
                       }
                       out.print("</table>");
                   }
                %>
            </div>
            
        </div>
        <jsp:include page="../comm/footer.jsp" flush="true"/>
    </div>
</body>
</html>